package com.springboot.servlet;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 1.@WebFilter 表示 Filter_是一个过滤器，并注入容器
 * 2.urlPatterns = {"/manger"} 当请求/manger资源时，过滤器会进行过滤
 * 3.在过滤器放行之后，经过拦截器，拦截器是否拦截要根据拦截器的拦截规则
 */
//@WebFilter(urlPatterns = {"/manger.html"})
@Slf4j
public class Filter_ implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("----filter-init----");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("----filter-doFilter----");
        HttpServletRequest httpServletRequest =
                (HttpServletRequest) servletRequest;
        log.info("过滤器直接处理的URI={}", httpServletRequest.getRequestURI());
        //直接放行
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {
        log.info("----filter-destroy----");
    }
}
